<?php

namespace app\admin\model\resources;
use app\common\model\resources\Resources as ResourcesModel;


/**
 * 资源模型
 * Class User
 * @package app\store\model
 */
class Resources extends ResourcesModel
{

    /**
     * 获取课件列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList()
    {
        return $this->where('is_delete', '=', 0)
            ->order(['resources_sort' => 'asc', 'create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);

    }



    /**
     * 新增记录
     * @param $data
     * @return false|int
     */
    public function add($data)
    {
        if (empty($data['resources_title'])) {
            $this->error = '请输入资源标题';
            return false;
        }
        if (empty($data['down_id'])) {
            $this->error = '请上传资源';
            return false;
        }

        if (empty($data['resources_content'])) {
            $this->error = '请输入资源内容';
            return false;
        }
        return $this->allowField(true)->save($data);
    }


    /**
     * 更新记录
     * @param $data
     * @return bool|int
     */
    public function edit($data)
    {
        if (empty($data['resources_title'])) {
            $this->error = '请输入资源标题';
            return false;
        }
        if (empty($data['down_id'])) {
            $this->error = '请上传资源';
            return false;
        }

        if (empty($data['resources_content'])) {
            $this->error = '请输入资源内容';
            return false;
        }
        return $this->allowField(true)->save($data) !== false;
    }

    /**
     * 软删除
     * @return false|int
     */
    public function setDelete()
    {
        return $this->save(['is_delete' => 1]);
    }





}
